<template>
  <div class="content-wraper">
    <div class="search-box">
      <el-form label-width="100px" :inline="true">
        <el-form-item label="工程名称">
          <el-input v-model="projName" />
        </el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
        <el-button type="warning" icon="el-icon-refresh" @click="reset()">重置</el-button>
        <el-button type="success" icon="el-icon-plus" @click="addProjectInfo()">新增</el-button>
      </el-form>
    </div>
    <div class="detail">
      <com-table :data="dataList" :columns="columns" :total="total" @pageChange="pageChange">
        <template v-slot:name="{row}">
          <a class="com-link" @click="viewDetail(row)">{{ row.name }}</a>
        </template>
        <template v-slot:options="{row}">
          <el-button type="primary" icon="el-icon-edit" size="mini" @click="editProjectInfo(row)">编辑</el-button>
          <el-button type="danger" icon="el-icon-delete" size="mini" @click="delProjectInfo(row)">删除</el-button>
        </template>
        <template v-slot:createTime="{row: {createTime}}">
          {{ dateFormat(createTime) }}
        </template>
        <template v-slot:projStatus="{row: {projStatus}}">
          {{ getDictName(projectInfoProjStatus, projStatus) }}
        </template>
        <template v-slot:projType="{row: {projType}}">
          {{ getDictName(projectInfoProjType, projType) }}
        </template>
        <template v-slot:projMode="{row: {projMode}}">
          {{ getDictName(projectInfoProjMode, projMode) }}
        </template>
        <template v-slot:projectDate="{row: {projectDate}}">
          {{ dateFormat(projectDate) }}
        </template>
        <template v-slot:planStartTime="{row: {planStartTime}}">
          {{ dateFormat(planStartTime) }}
        </template>
        <template v-slot:planFinishTime="{row: {planFinishTime}}">
          {{ dateFormat(planFinishTime) }}
        </template>
        <template v-slot:realStartTime="{row: {realStartTime}}">
          {{ dateFormat(realStartTime) }}
        </template>

      </com-table>
    </div>
    <add-project-info
      :show-modal.sync="showModal"
      :opt-type="optType"
      :data="unitDetail"
      @freshList="search"
    />
  </div>
</template>

<script>
import { getProjectInfoList, deleteProjectInfo } from '@/api/contractManage'
import moment from 'moment'
import { getDictName } from '@/utils/comm'
import addProjectInfo from '../generalContract/addProjectInfo.vue'
import { projectInfoProjStatus, projectInfoProjType, projectInfoProjMode } from '@/utils/dicData'
export default {
  name: 'ProjectInfo',
  components: {
    addProjectInfo
  },
  data() {
    return {
      projName: '',
      getDictName,
      projectInfoProjStatus,
      projectInfoProjType,
      projectInfoProjMode,

      dataList: [],
      total: 0,
      pageParams: {
        pageNum: 1,
        pageSize: 10
      },
      showModal: false,
      optType: 'add',
      unitDetail: {},
      columns: [
        {
          label: '工程名称',
          prop: 'projName',
          width: '350'
        },
        {
          label: '编制人',
          prop: 'founderName'
        },
        {
          label: '编制时间',
          prop: 'createTime',
          slot: 'createTime',
          width: '90'
        },
        {
          label: '承建单位',
          prop: 'constructionUnit',
          width: '250'
        },
        /* {
          label: '省份编码',
          prop: 'provinceCode'
        },
        {
          label: '省名称',
          prop: 'provinceName'
        },
        {
          label: '地市编码',
          prop: 'cityCode'
        },
        {
          label: '市名称',
          prop: 'cityName'
        },
        {
          label: '项目状态',
          prop: 'projStatus',
          slot: 'projStatus'
        },
        {
          label: '项目等级',
          prop: 'projLevel'
        },*/
        {
          label: '项目类型',
          prop: 'projType',
          slot: 'projType'
        },
        /* {
          label: '项目部电话',
          prop: 'projDepartmentPhone',
          width: '100'
        },
        {
          label: '项目部传真',
          prop: 'projDepartmentFax',
          width: '100'
        },
        {
          label: '项目部通讯地址',
          prop: 'projDepartmentAddress',
          width: '110'
        },
        {
          label: '项目部邮编',
          prop: 'projDepartmentPostCode',
          width: '100'
        },*/
        {
          label: '项目管理模式',
          prop: 'projMode',
          width: '100',
          slot: 'projMode'
        },
        {
          label: '项目经理',
          prop: 'projManager'
        },
        /* {
          label: '项目经理电话',
          prop: 'projManagerPhone',
          width: '100'
        },
        {
          label: '项目经理资质',
          prop: 'projManagerQualification',
          width: '100'
        },
        {
          label: '项目总工',
          prop: 'projChiefEngineer'
        },
        {
          label: '项目总工电话',
          prop: 'projChiefEngineerPhone',
          width: '100'
        },*/
        {
          label: '业主单位',
          prop: 'ownerUnit'
        },
        /* {
          label: '业主通讯地址',
          prop: 'ownerAddress',
          width: '100'
        },
        {
          label: '业主邮编',
          prop: 'ownerPostCode'
        },
        {
          label: '业主电话',
          prop: 'ownerPhone'
        },
        {
          label: '业主传真',
          prop: 'ownerFax'
        },
        {
          label: '设计单位',
          prop: 'designUnit'
        },
        {
          label: '设计人',
          prop: 'designPerson'
        },
        {
          label: '设计电话',
          prop: 'designPhone'
        },
        {
          label: '设计传真',
          prop: 'designFax'
        },*/
        {
          label: '监理单位',
          prop: 'supervisionUnit'
        },
        /* {
          label: '监理人',
          prop: 'supervisionPerson'
        },
        {
          label: '监理通讯地址',
          prop: 'supervisionAddress',
          width: '100'
        },
        {
          label: '监理邮编',
          prop: 'supervisionPostCode'
        },
        {
          label: '监理电话',
          prop: 'supervisionPhone'
        },
        {
          label: '监理传真',
          prop: 'supervisionFax'
        },
        {
          label: '中标资质',
          prop: 'bidQualification'
        },
        {
          label: '立项日期',
          prop: 'projectDate',
          slot: 'projectDate'
        },
        {
          label: '计划开始时间',
          prop: 'planStartTime',
          slot: 'planStartTime',
          width: '100'
        },
        {
          label: '计划完成时间',
          prop: 'planFinishTime',
          slot: 'planFinishTime',
          width: '100'
        },
        {
          label: '实际开始时间',
          prop: 'realStartTime',
          slot: 'realStartTime',
          width: '100'
        },
        {
          label: '描述',
          prop: 'description'
        },
        {
          label: '概况',
          prop: 'summary'
        },*/

        {
          fixed: 'right',
          label: '操作',
          width: '180',
          prop: 'options',
          slot: 'options'
        }
      ]
    }
  },
  mounted() {
    this.getDataList()
  },
  methods: {
    dateFormat(data) {
      if (data) {
        return moment(data).format('YYYY-MM-DD')
      } else {
        return ''
      }
    },
    pageChange(data) {
      this.pageParams = data
      this.getDataList()
    },
    getDataList() {
      const params = {
        ...this.pageParams,
        projName: this.projName
      }
      getProjectInfoList(params).then(res => {
        const { data, total } = res.data || {}
        if (data) {
          this.dataList = data
          this.total = total - 0
        }
      })
    },
    addProjectInfo() {
      this.optType = 'add'
      this.showModal = true
    },
    editProjectInfo(data) {
      this.optType = 'edit'
      this.unitDetail = data
      this.showModal = true
    },
    viewDetail(data) {
      this.optType = 'detail'
      this.unitDetail = data
      this.showAddFileModal = true
    },
    delProjectInfo(data) {
      this.$confirm('确定要删除该项目基本信息吗, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const { id } = data
        deleteProjectInfo({
          projectInfoId: id
        }).then(res => {
          const { code, msg } = res
          if (code === '0001') {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.getDataList()
          } else {
            this.$message({
              type: 'error',
              message: msg || '删除失败!'
            })
          }
        })
      }).catch(() => {
      })
    },
    search() {
      this.pageParams.pageNum = 1
      this.getDataList()
    },
    reset() {
      this.projName = ''
    }

  }
}
</script>

<style lang="scss" scoped>
.search-box {
  height: 50px;
}
.detail{
  height: calc(100% - 50px);
}
</style>
